home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / share / python-support / python-rdflib / rdflib / URLInputSource.py < prev    next >
Encoding:
Python Source  |  2007-04-04  |  747 b   |  27 lines

  1. from urllib2 import urlopen, Request
  2.  
  3. from xml.sax.xmlreader import InputSource
  4.  
  5. from rdflib import __version__
  6.  
  7. # TODO: add types for n3. text/rdf+n3 ?
  8. headers = {
  9.     'Accept': 'application/rdf+xml,application/xhtml+xml;q=0.5',
  10.     'User-agent':
  11.     'rdflib-%s (http://rdflib.net/; eikeon@eikeon.com)' % __version__
  12.     }
  13.  
  14.  
  15. class URLInputSource(InputSource, object):
  16.     def __init__(self, system_id=None):
  17.         super(URLInputSource, self).__init__(system_id)
  18.         self.url = system_id
  19.         # So that we send the headers we want to...
  20.         req = Request(system_id, None, headers)
  21.         file = urlopen(req)
  22.         self.setByteStream(file)
  23.         # TODO: self.setEncoding(encoding)
  24.  
  25.     def __repr__(self):
  26.         return self.url
  27.